package com.lenovo.manufacture.module;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.beardedhen.androidbootstrap.BootstrapLabel;
import com.lenovo.manufacture.Adapter.recAdapter;
import com.lenovo.manufacture.R;
import com.lenovo.manufacture.net.BaseActivity;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class module3 extends BaseActivity {

    @BindView(R.id.m3_rv)
    RecyclerView m3Rv;
    @BindView(R.id.m3_tv1)
    BootstrapLabel m3Tv1;
    @BindView(R.id.m3_tv2)
    BootstrapLabel m3Tv2;
    List<Map<String, String>> people;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_module3);
        ButterKnife.bind(this);
        init();
    }

    private void init() {
        dialog.show();
        m3Tv2.setTag(true);
        m3Tv1.setTag(true);
        async(data.getHrm(), v -> {
            people = v.getData();
            initlist();
        });
    }

    @SuppressLint("NewApi")
    private void initlist() {
        List<String> list = new ArrayList<>();
        final String[] s = {""};
        people.forEach(person -> {
            list.add(person.get("personName"));
            switch (person.get("type")) {
                case "0":
                    s[0] = "工程师";
                    break;
                case "1":
                    s[0] = "工人";
                    break;
                case "2":
                    s[0] = "技术人员";
                    break;
                case "3":
                    s[0] = "质检员";
                    break;
            }
            list.add(s[0]);
            list.add(decimalFormat.format(Integer.valueOf(person.get("price"))));
        });
        m3Rv.setLayoutManager(new GridLayoutManager(this, 3));
        m3Rv.setAdapter(new recAdapter(list));
        dialog.cancel();
    }

    @OnClick({R.id.m3_tv1, R.id.m3_tv2})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.m3_tv1:
                sort(people, "type", m3Tv1, "类型");
                break;
            case R.id.m3_tv2:
                sort(people, "price", m3Tv2, "薪资");
                break;
        }
        initlist();
    }
}
